<template>
	<view class="fb-content">
		<view class="tx-mp">
			<u--textarea confirmType="done" v-model="textVal" height="160" placeholder="请输入您宝贵的意见或建议.(500字以内)" count maxlength="500" ></u--textarea>
		</view>
		<view>
			<text>{{tx}}</text>
		</view>
		<view class="btn-box">
			<u-button text="提交" type="primary" shape="circle" customStyle="width: 80%;" @click="btnCommit"></u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
	
<script>
	import {commitFeedback} from '@/utils/api.js'
	export default {
		data() {
			return {
				textVal: '',
				tx: '欢迎您为我们提出宝贵的意见和建议, 您留下的任何信息都将用来改善我们的软件。',
			}
		},
		methods: {
			async btnCommit(){
				let msg = '提交反馈信息成功'
				let k = 1
				if(this.textVal.trim() != ''){
					await commitFeedback({message: this.textVal}).then(res=>{
						k = 0
					}).catch(err=>{
						msg = err.message
					})
				}else {
					msg = '请填写要反馈的内容哦!'
				}
				
				getApp().globalData.toast[k].message = msg
				this.$refs.uToast.show({
					...getApp().globalData.toast[k],
					complete() {
						if(k == 0){
							uni.$u.route({
								type: 'back',
								delta: 1,
								animationType: 'pop-out',
								animationDuration: 200
							});
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fb-content{
		.tx-mp {
			padding: 10rpx;
			margin: 60rpx 20rpx 20rpx 20rpx;
		}
		view:nth-child(2){
			margin: 20rpx;
			text-align: center;
			color: #767373;
		}
		.btn-box {
			position: fixed;
			bottom: 40rpx;
			left: 0;
			width: 100%;
			text-align: center;
		}
	}
</style>
